package com.lxy.demo.service;

import com.lxy.demo.dao.PersonsMapper;
import com.lxy.demo.entity.Persons;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

@Transactional
@Service
public class PersonsServiceImpl implements PersonsService{

    //(required = false)忽略接口是否有实现类
    @Autowired(required = false)
    private PersonsMapper personsMapper;

    @Override
    public List<Persons> findPersons() {
        return personsMapper.selectPersons();
    }

    @Override
    public Boolean addUser(Integer id, Persons persons) {
        try {
            int i = personsMapper.deleteByPrimaryKey(id.longValue());
            int y = personsMapper.insert(persons);
            return true;
        }catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return false;
        }
    }
}
